﻿using M_Purchase.Api.Appliction.Command.AllocateCommand;
using M_Purchase.Domain;
using M_Purchase.Repository.PurchaseInterface;
using MediatR;
using System.Security.Cryptography.Xml;

namespace M_Purchase.Api.Appliction.CommandHandlers.AllocateCommandHandler
{
    /// <summary>
    /// 更新调拨命令处理器
    /// </summary>
    public class UpdateAllocateCommandHandler : IRequestHandler<UpdateAllocateCommand, int>
    {
        /// <summary>
        /// 调拨仓储接口
        /// </summary>
        protected readonly IAllocateRepository allocateRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="allocateRepository">调拨仓储接口</param>
        public UpdateAllocateCommandHandler(IAllocateRepository allocateRepository)
        {
            this.allocateRepository = allocateRepository;
        }

        /// <summary>
        /// 更新调拨信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(UpdateAllocateCommand request, CancellationToken cancellationToken)
        {
            return await allocateRepository.UpdateAsync(new Allocate()
            {
                AllocateId = request.AllocateId,
                AllocateNumber = request.AllocateNumber,
                AllocateDate = request.AllocateDate,
                AllocateNum=request.AllocateNum,
                AllocatePerson=request.AllocatePerson,
                AllocateReason=request.AllocateReason,
                Notes=request.Notes,
                Associate=request.Associate,
                Transport=request.Transport,
                ApprovedDate=request.ApprovedDate,
                Reviewer=request.Reviewer,
                AllocateStatus=request.AllocateStatus,
                sub = request.sub,
                sid = request.sid,
                jti = request.jti,
                CreatedBy = request.CreatedBy,
                CreatedDate = request.CreatedDate,
                UpdatedBy = request.UpdatedBy,
                UpdatedDate = DateTime.Now,
                DeletedBy = request.DeletedBy,
                DeletedDate = request.DeletedDate,
                IsDeleted = request.IsDeleted
            });
        }
    }
}
